﻿using Bling.DSL;
using Bling.Core;
using Bling.WPF;
using Bling.Util;


using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System;


namespace NewBlingExample {
  class Example : Canvas {
    public Example() {
      var Canvas = this.Bl();
      Canvas.Background = Brushes.White;
      var r = new Random();
      var lineA = new LineBl(Canvas) {
        Start = new ThumbBl(Canvas) { Background = Brushes.Red, CanDrag = true, CenterPosition = Canvas.Size * r },
        End = new ThumbBl(Canvas) { Background = Brushes.Blue, CanDrag = true, CenterPosition = Canvas.Size * r },
      };
      var lineB = new LineBl(Canvas) {
        Start = new ThumbBl(Canvas) { Background = Brushes.Green, CanDrag = true, CenterPosition = Canvas.Size * r },
        End = lineA.Start,
      };
      new LineBl(Canvas) {
        Start = lineB.Start,
        End = lineA.End,
      };
      PointBl A = lineA.Start, B = lineA.End, C = lineB.Start;
      var angle = (C - B).Angle.Inverse; // + .5.Bl().PI()).Inverse;
      var lbl = new LabelBl(Canvas) {
        RightBottom = Canvas.CenterSize, Content = (C - B).Angle.Normalize.PI.RoundN(100d).ToStringBl(),
      };

      /*
      var lineC = new LineBl(Canvas) { Start = B.Rotate(A,angle), End = C.Rotate(A,angle), Stroke = { Brush = Brushes.Red } };
      var lineD = new LineBl(Canvas) { Start = A, End = lineC.Start, Stroke = { Brush = Brushes.Red } };
      var lineE = new LineBl(Canvas) { Start = A, End = lineC.End, Stroke = { Brush = Brushes.Red } };
      var Hx = new PointCl(A.X, lineC.Start.Y);
      new ThumbBl(Canvas) { Background = Brushes.Purple, CenterPosition = Hx };
      var H = Hx.Rotate(A, angle.Inverse);

       */
      new ThumbBl(Canvas) { Background = Brushes.LightPink, CenterPosition = A.TriangleBase(B,C) };

      /*
      var Bx = B.Rotate(A, angle);
      new LineBl(Canvas) { Start = A, End = Bx, Stroke = { Brush = Brushes.Red } };

      var Hx = new PointCl(A.X, Bx.Y);
      new LineBl(Canvas) { Start = A, End = Hx, Stroke = { Brush = Brushes.Blue } };
      var H = Hx.Rotate(A, angle.Inverse);
      new LineBl(Canvas) { Start = Hx, End = H, Stroke = { Brush = Brushes.Green } };
      */


    }

    [STAThread]
    public static void MainX(string[] args) {
      var win = new Window() { Title = "Getting Started", Content = new Example() };
      new Application().Run(win);
      return;
    }
  }
}